package com.auxgroup.hr.front.site.co.modPerson;

import javax.annotation.Resource;
import javax.validation.Valid;

import com.auxgroup.hr.front.site.inteceptor.SessionGain;
import com.auxgroup.hr.front.site.vo.modperson.ModSocialQueFrom;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.auxgroup.hr.front.commons.vo.BaseResponseVO;
import com.auxgroup.hr.front.commons.vo.UserDTO;
import com.auxgroup.hr.front.dao.domain.PsCModSocial;
import com.auxgroup.hr.front.dao.domain.PsCModSocialPrimary;
import com.auxgroup.hr.front.dozer.IObjectMapper;
import com.auxgroup.hr.front.service.modperson.ModSocialService;
import com.auxgroup.hr.front.site.co.BaseCO;
import com.auxgroup.hr.front.site.inteceptor.SessionGain;
import com.auxgroup.hr.front.site.vo.modperson.ModSocialQueFrom;

/**
 * 公积金流程信息CO
 * @author lvliuhao
 * @version 创建时间：180526 
 */
@RestController
@RequestMapping("${auxgroup.hr.contextPath}/modSocial")
public class ModSocialCO extends BaseCO {

	private static final Logger logger = LoggerFactory.getLogger(ModSocialCO.class);

	@Autowired
	public ModSocialService modSocialService;

	@Resource(name = "dozerMapper")
	protected IObjectMapper objectMapper;

	/**
	 * 保存公积金流程信息
	 * @param hireId
	 * @return
	 */
	@PostMapping(value = "/save")
	public BaseResponseVO save(@Valid ModSocialQueFrom modSocialQueFrom, @SessionGain("user") UserDTO  user, BindingResult binding) {
		logger.info("saveModSocial param= {}", modSocialQueFrom);
		//表单校验
		super.assertValidation(binding);
		PsCModSocialPrimary primary = objectMapper.map(modSocialQueFrom, PsCModSocialPrimary.class);
		PsCModSocial modSocial = modSocialService.getModSocial(primary);
		if(modSocial!=null){
			objectMapper.map(modSocialQueFrom, modSocial,"notCopyNull_modSocial");
		}else{
			modSocial = objectMapper.map(modSocialQueFrom, PsCModSocial.class);
		}
		modSocial = modSocialService.save(modSocial,user);
		if(modSocial.getEmplid() != null){
			return buildRespone(true);
		}
		return buildRespone(false);
		
	}
	
	/**
	 * 获取公积金流程信息
	 * @param hireId
	 * @return
	 */
	@GetMapping(value = "/getOne")
	public BaseResponseVO getOne(PsCModSocialPrimary primary) {
		logger.info("getModSocial param= {}", primary);
		PsCModSocial modSocial = modSocialService.getModSocial(primary);
		return buildRespone(modSocial);
	}

}
